package com.example.myapplication5;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class TranslationFromActivity extends AppCompatActivity {
    private Button mButton1;
    private Button mButton2;
    private Button mButton3;
    private Button mButton4;
    private ImageView mImage;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_from);
        mButton1 = findViewById(R.id.button1);
        mButton2 = findViewById(R.id.button2);
        mButton3 = findViewById(R.id.button3);
        mButton4 = findViewById(R.id.button4);
        mImage = findViewById(R.id.image);
        addListener(mButton1, 1);
        addListener(mButton2, 2);
        addListener(mButton3, 3);
        addListener(mButton4, 4,
                new Pair<>(mButton1, "button1"),
                new Pair<>(mButton2, "button2"),
                new Pair<>(mButton3, "button3"),
                new Pair<>(mButton4, "button4"),
                new Pair<>(mImage, "image"));
    }

    private void addListener(Button button, int flag, Pair<View, String>... sharedElements) {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(TranslationFromActivity.this, TranslationToActivity.class);
                intent.putExtra("flag", flag);
                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(TranslationFromActivity.this,
                        sharedElements).toBundle());
            }
        });
    }
}